---
title: Serial Peripheral Interface (SPI)
---
<h1>SPI Application</h1>

<p>This application allows for communication by SPI,
the Serial Peripheral Interface.  Use the following pinout,
which is very similar to the JTAG pinout.</p>

<!--
<a href="http://www.flickr.com/photos/travisgoodspeed/3593286652/"
title="GoodFET SPI Pinout by Travis Goodspeed, on Flickr">
<img src="http://farm3.static.flickr.com/2466/3593286652_f849e74d18.jpg"
width="500" height="290" alt="GoodFET SPI Pinout" /></a>
-->

<a href="http://www.flickr.com/photos/travisgoodspeed/3839800528/"
title="GoodFET SPI Flash Pinout by Travis Goodspeed, on Flickr">
<img src="http://farm3.static.flickr.com/2577/3839800528_65e6430feb_o.png"
width="420" height="412" alt="GoodFET SPI Flash Pinout" /></a>


<h2>Clients</h2>

<p>A Python
client, <a href="/clients/goodfetspiflash/">goodfet.spiflash</a>, is
quite effective at reading, writing, and erasing SPI flash chips.</p>
<p>In addition to that, another client, <a href="/clients/goodfetzensys">goodfet.zensys</a>,
is dedicated to Zensys Z-Wave ASICs and provides read/write/erase capabilities.</p>

<h2>Development</h2>

<p>Prior to any transactions, the SETUP (0x10) verb should be sent to the
SPI application to properly set the I/O directions.</p>

<p>SPI is based upon the exchange of information as a duplex transaction.
As such, the READ (0x00) and WRITE (0x01) verbs are identical.  Each transmits
the bytes of the data buffer through MOSI, returning the result through
MISO.  !SS is dropped low at the beginning of a transaction,
then raised after all bytes have been exchanged.</p>

<p>There is also a <a href="http://travisgoodspeed.blogspot.com/2009/06/spi-client-tutorial-for-goodfet.html">
full tutorial</a> for the SPI application.</p>

<h2>Verbs</h2>

<p>The following verbs are supported.  The Write-Enable command is implied
by those that write flash memory, such as POKE and SPI_ERASE.</p>

<table border="1">
<tr><th>Hex</th><th>#define</th><th>Description</th></tr>
<tr><td>0x00</td><td>READ</td><td>Exchange data.</td></tr>
<tr><td>0x01</td><td>WRITE</td><td>Exchange data.</td></tr>
<tr><td>0x02</td><td>PEEK</td><td>Read 64 bytes from supplied 24-bit address.</td></tr>
<tr><td>0x03</td><td>POKE</td><td>Write data to flash at 24-bit address.</td></tr>
<tr><td>0x10</td><td>SETUP</td><td>Configure I/O pins.</td></tr>
<tr><td>0x20</td><td>START</td><td>Start a transaction.</td></tr>
<tr><td>0x21</td><td>STOP</td><td>Stop a transaction.</td></tr>
<tr><td>0x7E</td><td>NOK</td><td>No Operation</td></tr>

<tr><td>0x80</td><td>SPI_JEDEC</td><td>Grab 3-byte JEDEC ID.</td></tr>
<tr><td>0x81</td><td>SPI_ERASE</td><td>Erase a Flash EEPROM.</td></tr>
<tr><td>0x82</td><td>SPI_RW_EM260</td><td>SPI exchange with an EM260.</td></tr>
<tr><td>0x83</td><td>SPI_ZENSYS_ENABLE</td><td>Zensys "Program enable" command.</td></tr>
<tr><td>0x84</td><td>SPI_ZENSYS_WRITE3_READ1</td><td>Zensys specific command that reads 1 byte of flash.</td></tr>
<tr><td>0x85</td><td>SPI_ZENSYS_WRITE2_READ2</td><td>Zensys specific command that reads 2 bytes of flash.</td></tr>
</table>
